package struts.form;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import struts.util.XmlBean;
//import struts.util.XmlParse;
import struts.util.XmlConfigParse;

/**
 * 在web.xml文件中初始化struts配置信息
 * 
 * @author zhouhong
 * @date 2014-9-21 新建
 */
public class ActionListener implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("信息：系统无法注销！");
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		String appRealPath = sce.getServletContext().getRealPath("/");
		String configPath = appRealPath + "/WEB-INF/struts-config.xml";
		System.out.println(configPath);
		try {
			Map<String,XmlBean> map = XmlConfigParse.parseXml(configPath);
			sce.getServletContext().setAttribute("struts", map);
//			System.out.println("++++++++++++++++++++++++++");
//			System.out.println("-------" + map);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
//		System.out.println("=======================");
//		System.out.println("configPath : " + configPath);
		System.out.println("信息：系统已经加载完成！");
//		System.out.println("=======================");
	}

}
